BUI.use(['bui/tree','bui/data','bui/toolbar','bui/editor','bui/menu','bui/overlay','bui/form','bui/select','bui/slider','bui/uploader'],function (Tree,Data,Toolbar,Editor,Menu,Overlay,Form,Select,Slider,Uploader) {
// KISSY.use(['bui/tree','bui/data','bui/toolbar','bui/editor','bui/menu','bui/overlay','bui/form','bui/select','bui/slider','bui/uploader'],function(S,Tree,Data,Toolbar,Editor,Menu,Overlay,Form,Select,Slider,Uploader){
	function showDialog(title,msg,input){
		BUI.Message.Show({
			"msg" : "<h3>"+title+"</h3>"+(msg?msg:""),
			"icon" : 'question',
			"mask":false,
			"buttons" : [
			  {
				text:'确认',
				elCls : 'button button-mini js-close',
				handler : function(){
					this.close();
				}
			  }
			]
		});
	}
	function showDialog1(html,title,bts,w,h,cls,msk){
		w=w?w:"300";
		h=h?h:"200";
		title=title?title:"提示信息";
		bts=bts?bts:[{
						text:'关闭',
						elCls : 'button',
						handler : function(){
						  this.close();
						}
					  }
					];
		  var dlg = new Overlay.Dialog({
            "title":title,
            "width":w,
            "height":h,
			"elCls" : cls,
            //配置DOM容器的编号
			"mask":msk,
            "buttons":bts,
			"bodyContent":html
          });
		  dlg.show();
	}
	function removeGift(gid){
		$.ajax(
		{"url":"/?m=Kxdr&c=Gameset&a=del_gift",
			"data":{"gid":gid},				  
			"dataType": "json",
			"success":function(data,status){
				if(data.hasError){
					showDialog("删除奖品出错！");
				}else{
					giftstore.load();
					$(".gift"+gid).remove();
				}
			}
		});
	}
	function addNewNode(selectedNode){
		if(selectedNode.leaf==true){
			showDialog("不能在此添加项目，请选择一个类目",250,150);
		}else{
			var cls = "",leaf=true;
			if(selectedNode.team_type=="cat" || $(".team_type").val()=="team"){
				cls="x-tree-elbow-dir";leaf=false;
			}
			if(selectedNode.id==0){
				selectedNode.game_category = $(".game_category").val();
				selectedNode.privat_league_id = $(".privat_league_id").val();
				selectedNode.league_id = $(".league_id").val();
				selectedNode.league_name = $(".league_name").val();
				selectedNode.team_type = $(".team_type").val();
			}
			var newNode = {"text" : '新增活动项目',"fid":selectedNode.id,"cls":cls,"leaf":leaf,"game_id":selectedNode.game_id,
				"game_category":selectedNode.game_category,
				"privat_league_id":selectedNode.privat_league_id,
				"league_id":selectedNode.league_id,
				"league_name":selectedNode.league_name,
				"team_type":selectedNode.team_type
			};
			newNode = store.add(newNode,selectedNode);
			tree.expandNode(selectedNode);
			showEditor(newNode);
		}
	}
	function deleteNode(node){
		var dlg = new Overlay.Dialog({
		"title":"请确认删除",
		"width":200,
		"height":150,
		//配置DOM容器的编号
		"mask":true,
		"buttons":[{
                text:'删除',
                elCls : 'button button-danger',
                handler : function(){
                  delete_byid(node);
				  this.close();
                }
              },{
                text:'关闭',
                elCls : 'button',
                handler : function(){
                  this.close();
                }
              }],
		"bodyContent":"注意，一旦删除，将会把下一级内容全部删除。请谨慎选择。"
		});
		dlg.show();
		  
		var delete_byid = function(node){
			var tp = $(".js-load").attr("data-tp");
			$.post("/?m=Kxdr&c=Gameset&a=del_"+tp,
			  {
				"id":node.id,
			  },
			  function(data,status){
				if(status){
					store.remove(node);
				}else{
					showDialog("删除数据出错！请联系客服："+data.error);
				}
			});
		}
	}
	var addp = new Overlay.Dialog({
		title:'添加到活动',
		width:600,
		height:400,
		//配置DOM容器的编号
		contentId:'addplayer',
		success:function () {
			if(playerform.isValid()){
				var title = $(".player_title").val();
				var player_name = $(".js-dwdy").val();
				var player_id = $(".js-playerid").val();
				var cffs = $(".js-cffs").val();
				var cffsval = $(".js-cffsval").val()
				var zmc = $(".js-zmcval").val();
				var player_descrip = $(".player_descrip").val();
				var target_data = $(".target_data").val();
				var target_data_sign = $('.target_data_sign:checked').val();
				var target_data_very = $('.very_value').attr("checked");
				if($(".js-cffsval").val()=="input"){
					$.ajax(
					{"url":"/?m=Kxdr&c=Gameset&a=add_cffs",
					  "data":{"cffs":cffs},
					  "dataType": "json",
					  "type": "POST",
					  "success":function(data,status){}
					});
				}
				$.ajax(
				{"url":"/?m=Kxdr&c=Gameset&a=add_event_player",
					"data":{
						"title":title,
						"player_id":player_id,
						"cffs":cffs,
						"cffsval":cffsval,
						"zmc":zmc,
						"player_descrip":player_descrip,
						"target_data":target_data,
						"target_data_sign":target_data_sign,
						"target_data_very":target_data_very,
						"player_name":player_name
				  },
				  "dataType": "json",
				  "type": "POST",
				  "success":function(data,status){
					if(status){
						var html ='<div class="well well-small button-tabs player'+data.epid+'"><h4 class="span13">['+$(".js-dwdy").val()+']&nbsp;['+title+']&nbsp;['+cffs+']&nbsp;['+$(".js-zmctext").val()+']&nbsp;</h4><button class="button button-mini button-warning js-delplayer pull-right"  data-id="'+data.epid+'">删除</button></div>';
						$(html).appendTo(".js-player-list");
						$(".js-delplayer").on("click",function(){
							var epid = $(this).attr("data-id");
							remove_event_player(epid);
						});
						$(".js-noplayer").remove();
						addp.close();
					}else{
						showDialog("添加数据出错！请联系客服："+data.error);
					}
				}});
			}
		}
	});
	function remove_event_player(epid){
		$.ajax(
		{"url":"/?m=Kxdr&c=Gameset&a=del_event_palyer",
		  "data":{"epid":epid},
		  "dataType": "json",
		  "success":function(data,status){
			  if(data.status==1){
				  $(".player"+epid).remove();
			  }else{
				  showDialog("删除参赛队伍失败");
			  }
		  }
		});
	}
	$(".js-delplayer").on("click",function(){
		var epid = $(this).attr("data-id");
		remove_event_player(epid);
	});
	function addPlayer(node){
		addp.show();
	}
       //数据缓冲类
	function getData(url,title,root){
		root=root?root:{                  //由于要显示根节点，所以需要配置根节点
			  "id" : 0,
			  "text" : title,
			  "expanded" : false,
			  "children" : []
			};
      var store = new Data.TreeStore({
          "root" : root,
          "pidField" : 'fid',
          "url" : url,
          "autoLoad" : true,
		  "proxy" : {
			  "method" : 'post',
			  "dataType" : 'json'
			}
        });
		store.on('beforeprocessload',function(ev){
			if(ev.data.hasError){
				showDialog(ev.data.error);
				$(".bui-tree-item-loading").removeClass("bui-tree-item-loading");
			}
		});
		// store.on("load",function(ev){
			// caishenme.render();
		// });
	  return store;
	}
	var store = getData($(".js-load").attr("data-url"),$(".js-load").attr("data-rtitle"));
	var tree = new Tree.TreeList({
        render : '#t1',
        showLine : true,
        height:300,
        store : store,
        // checkType : 'all',
        showRoot : true
      });
      tree.render();
		var menu = new Menu.ContextMenu({
        children : [
          {
            iconCls:' icon-plus',
            text : '添加到活动',
            listeners:{
              'click':function(){
				  var selectedNode = tree.getSelected();
				  if(selectedNode.id>0){
					addPlayer(selectedNode);
				  }else{
					  showDialog("请选择一个队伍！");
				  }
				}
            }
          },
          {xclass:'menu-item-sparator'},
		  {
            iconCls:' icon-plus',
            text : '新增',
            listeners:{
              'click':function(){
				  var selectedNode = tree.getSelected();
				  if(selectedNode.id>0){
				  addNewNode(tree.getSelected());
				  }
				}
            }
          },
          {xclass:'menu-item-sparator'},
          {
            iconCls:'icon-remove',
            text: '删除',
			listeners:{
				"click":function(){
				  var selectedNode = tree.getSelected();
				  if(selectedNode){
					deleteNode(selectedNode);
				  }
				}
			}
          },
          {
            iconCls:'icon-pencil',
            text : '编辑',
            listeners:{
              'click':function(){showEditor(tree.getSelected())}
            }
          }
        ]
      });
	  tree.on('itemcontextmenu',function(ev){
        var item = ev.item;
        tree.setSelected(item);
		if(item){
			$(".js-dwdy").val(item.text);
			$(".js-dwdy").focus();
			menu.set('xy',[ev.pageX,ev.pageY]);
			menu.show();
		}
        return false; //prevent the default menu
      });
      var store = tree.get('store'),
        editor = new Editor.Editor({
          field : { //设置编辑的字段
            rules : {
              required : true
            }
          },
          autoUpdate : false, //不自动更新对应DOM的文本，而使用store更新数据
          changeSourceEvent : null
        });
      editor.render();
 
      editor.on('accept',function(){
        var text = editor.getValue(),
		    action="add",
            node = editor.get('curNode');
		if(node.id){
			action="edit";
		}
		  	var tp = $(".js-load").attr("data-tp");
			$.ajax(
			{"url":"/?m=Kxdr&c=Gameset&a=edit_"+tp,
				"data":{
				"tp":tp,
				"name":text,
				"fid":node.fid,
				"id":node.id,
				"game_id":node.game_id,
				"game_category":node.game_category,
				"privat_league_id":node.privat_league_id,
				"league_id":node.league_id,
				"league_name":node.league_name,
				"team_type":node.team_type,
				"action":action
			  },
			  "dataType": "json",
			  "success":function(data,status){
				if(status){
					node.text = text;
					node.id = data.id;
					node.privat_league_id=data.id;
					node.league_id=data.league_id;
					node.league_name=data.name;
					node.team_type=data.team_type;
					store.update(node);
				}else{
					showDialog("添加数据出错！请联系客服："+data.error);
				}
			}});
      });
 
      //显示编辑器
      function showEditor(node){
        var element = tree.findElement(node);
        editor.setValue(node.text);
        editor.set('curNode',node); //缓存当前编辑的记录
        editor.set('align',{ //设置对齐
          node : $(element).find('.x-tree-icon-wraper'),
          points : ['tr','tl']
        });
        editor.show();
        editor.focus(); //获取焦点
 
      }
      // 单击添加
      tree.on('itemdblclick',function(ev){
        var node = ev.item;
		var tp = $(".js-load").attr("data-tp");
		if(ev.item.id>0 && tp=="player"){
			addPlayer(node);
		}
      });
      //双击编辑
      // tree.on('itemdblclick',function(ev){
        // var node = ev.item;
		// if(ev.item.id>0){
			// showEditor(node);
		// }
      // });
	  //移除动作
      tree.on('itemremoved',function(ev){
        var node = ev.item;
      });
	  //选中itemclick( e )
	  tree.on('itemclick',function(ev){
        var node = ev.item;
		if(node.id>0){
			$(".js-hdid").val(node.id);
			$(".js-playerid").val(node.id);
			$(".js-kxby").val(node.text);
			$(".js-kxby").focus();
			$(".js-bssj").val(node.start_time);
			$(".js-bssj").focus();
			$(".js-bsms").val(node.description);
			$(".js-bsms").focus();
			if(node.pic_url){
				$(".js-picurl").val(node.pic_url);
				if(node.pic_url.indexOf("kxdr")>0){
					$(".js-picview").attr("src",node.pic_url+"@315h_315w.jpg");
				}else{
					$(".js-picview").attr("src",node.pic_url+"_315x315.jpg");
				}
			}else{
				$(".js-picurl").val("");
				$(".js-picview").attr("src","https://img.alicdn.com/tps/i1/TB1erhHHpXXXXbFXFXXXykfYFXX-315-175.png");
			}
			$(".game-title").text(node.text);
			$(".game_category").val(node.game_category);
			$(".privat_league_id").val(node.privat_league_id);
			$(".league_id").val(node.league_id);
			$(".league_name").val(node.league_name);
			$(".team_type").val(node.team_type);
			$(".js-dwdy").val(node.text);
			$(".js-dwdy").focus();
		}else{
			$(".js-hdid").val("");
			$(".js-kxby").val("");
			$(".js-bssj").val("");
			$(".js-bsms").val("");
		}
      });
	  //更新项目itemupdated( e )

	  tree.on('itemupdated',function(ev){
		var node = ev.item;
		$(".game-title").text(node.text);
		$(".game_category").val(node.game_category);
		$(".privat_league_id").val(node.privat_league_id);
		$(".league_id").val(node.league_id);
		$(".league_name").val(node.league_name);
		$(".team_type").val(node.team_type);
		$(".js-dwdy").val(node.text);
		$(".js-dwdy").focus();
        // alert(node.text);
        // alert(node.fid);
      });
 
      var bar = new Toolbar.Bar({
        render : '#tbar',
        elCls : 'button-group',
        children : [
          {
           
            elCls : 'button button-small',
            content : '新增',
            handler : function(){
                var selectedNode = tree.getSelected();
				if(!selectedNode){
					BUI.Message.Alert("请选择一个项目",'error');
				}
				if(selectedNode.id==0 && $(".step").val()!="step2"){
					BUI.Message.Alert("不能在这里新建活动！",'error');
				}else{
					addNewNode(selectedNode);
				}
            }
          },
          {
            
            elCls : 'button button-small',
            content : '删除',
            handler : function(){
              var selectedNode = tree.getSelected();
              if(selectedNode){
				deleteNode(selectedNode);
              }
              
            }
          }
        ]
      });
      bar.render();
 
 
      
    //});
	//BUI.use(['bui/form','bui/select','bui/overlay','bui/slider','bui/uploader'],function(Form,Select,Overlay,Slider,Uploader){
    var playerform =  new Form.HForm({
        srcNode : '#J_Form',
        defaultChildCfg : {
          validEvent : 'blur' //移除时进行验证
        }
      });
	  playerform.render();
    var items = [
          {text:'不需要',value:'0'},
          {text:'10积分',value:'10'},
          {text:'100积分',value:'100'},
          {text:'1000积分',value:'1000'},
          {text:'其他数量请输入',value:'input'}
        ],
        select = new Select.Select({  
          render:'#s1',
          valueField:'.js-cyjf',
          items:items
        });
    select.render();
    select.on('change', function(ev){
		if(ev.item.value=="input"){
			// select.hide();
			$(".js-jfinput").show();
			$(".js-jfinput").focus();
		}else{
			$(".js-jfinput").hide();
			$(".js-jfinput").val(ev.item.value);
		}
    });
    // var items1 = [
          // {text:'猜金牌',value:'gold'},
          // {text:'猜胜负',value:'win'},
          // {text:'猜得分',value:'score'},
          // {text:'猜犯规',value:'illegality'},
          // {text:'预测其他数据请添加',value:'input'},
        // ];
	var s1store = new Data.Store({
      url : '/?m=Kxdr&c=Gameset&a=get_cffs&gcat='+$(".game_category").val(),
      autoLoad : true,
    });
		// s1store.on("beforeprocessload",function(ev){
			// // alert(ev.data[0].text);
		// });
		// s1store.on("load",function(ev){
			// caishenme.render();
		// });
    var caishenme = new Select.Select({  
          render:'#s2',
          valueField:'.js-cffsval',
		  store:s1store
        });
	var p=false;//是否猜数据的开关
	caishenme.render();
	caishenme.on('change', function(ev){
		if(ev.item.value=="input"){
			$(".js-cffs").show();
			$(".js-cffs").focus();
			$(".js-cffsval").val("");
		}else{
			$(".js-cffs").hide();
			$(".js-cffs").val(ev.item.text);
			$(".js-cffsval").val(ev.item.value);
			$(".js-cffsval").blur();
		}
		
		if(ev.item.value=="win" || ev.item.value=="draw"){
			// 猜胜负和平局时，不可以猜数据
			if(!p){
				zenmecai_val.pop();
				zenmecai.set("items",zenmecai_val);
				zenmecai.render();
				p=true;
			}
		}else{
			if(p){
				zenmecai_val.push({text:'猜数据',value:'0'});
				zenmecai.set("items",zenmecai_val);
				zenmecai.render();
				p=false;
			}
		}
		
		// $(".js-target_data").hide(); //无论猜什么，先隐藏预设数据，清空预设数据
		$(".target_data").val(0);
    });
    var items2 = [
          {text:'立即截止',value:'0'},
          {text:'10分钟',value:'10'},
          {text:'20分钟',value:'20'},
          {text:'30分钟',value:'30'},
          {text:'1小时',value:'60'},
          {text:'8小时',value:'480'},
          {text:'12小时',value:'720'},
          {text:'24小时',value:'1440'},
          {text:'其他时间请输入',value:'input'},
        ],
    select2 = new Select.Select({  
          render:'#s3',
          valueField:'.js-jzsjval',
          items:items2
        });
    select2.render();
	select2.on('change', function(ev){
		if(ev.item.value=="input"){
			// select.hide();
			showDialog("手动输入时，请填写分钟数。小时、天数都需要换算成分钟数填入。");
			$(".js-jzsj").show();
			$(".js-jzsj").focus();
		}else{
			$(".js-jzsj").hide();
			$(".js-jzsj").val(ev.item.value);
		}
    });
	var zmc = $(".zmc").val();
	//除猜数据（0）以外,只有猜中和没猜中两种情况
	var y_or_n = [
          {text:'没猜中',value:'-1'},
          {text:'完全猜中',value:'0'}
        ];
	var score = [
          {text:'没猜中',value:'-1'},
          {text:'完全猜中',value:'0'},
          {text:'差1分猜中',value:'1'},
          {text:'差2分猜中',value:'2'},
          {text:'差5分猜中',value:'5'},
          {text:'其他猜分情况',value:'input'},
        ];
	if(zmc>0 && zmc!=4){
		var items3 = y_or_n;	
	}else{
		var items3 = score;
	}
	//选择猜分差距的控件
    var select3 = new Select.Select({  
          render:'#s4',
          valueField:'.js-cfcjval',
          items:items3
        });
    select3.render();
	select3.on('change', function(ev){
		if(ev.item.value=="input"){
			// select.hide();
			$(".js-cfcj").show();
			$(".js-cfcj").focus();
		}else{
			$(".js-cfcj").hide();
			$(".js-cfcj").val(ev.item.value);
		}
    });
	
	var giftstore = new Data.Store({  //自动读取后台奖品数据
      url : '/?m=Kxdr&c=Gameset&a=get_gifts',
      autoLoad : true,
    });
	//选择可获取奖品的控件
    select4 = new Select.Select({  
		  elCls : 'pull-left',
          render:'#s5',
          valueField:'.js-hqjpval',
          store:giftstore
        });
    select4.render();
	select4.on("change",function(ev){
		$(".gift-name").val(ev.item.name);
		$(".gift-id").val(ev.item.id);
		$(".gift-type").val(ev.item.type);
		$(".js-gift_pic").val(ev.item.pic_url);
		slider1.slideTo(0);
		slider1.set('max',ev.item.quantity>=0?ev.item.quantity:0);
		slider1.render();
	});
    var items5 = [
          {text:'先领先得',value:'first_get'},
          {text:'先猜先得',value:'first_guess'},
          {text:'概率抽奖',value:'lottery'},
          {text:'订单兑奖',value:'order'},
          {text:'积分兑奖',value:'jifen'},
          {text:'勋章兑奖',value:'metal'},
          {text:'收藏单品',value:'collect'},
          {text:'加购物车',value:'addcart'},
          {text:'炫耀得奖',value:'friend_show'},
          // {text:'晒单得奖',value:'6'},
          // {text:'互动得奖',value:'4'},
          // {text:'加购物车得奖',value:'4'},
          // {text:'回帖得奖',value:'7'},
        ],
	// 选择获取方式的控件
    select5 = new Select.Select({  
          render:'#s6',
          valueField:'.js-hqfsval',
          items:items5
        });
    select5.render();
	select5.on('change', function(ev){
		$(".js-set-dddj").hide();
		$(".js-set-jpgl").hide();
		$(".js-ext").hide();
		switch(ev.item.value){
			case "lottery":
			$(".js-set-jpgl").show();
			break;
			case "order":
			$(".js-set-dddj").show();
			break;
			case "jifen":
			$(".js-set-jifen").show();
			break;
			case "metal":
			$(".js-set-metal").show();
			break;
			case "collect":
			$(".js-set-item").show();
			break;
			case "addcart":
			$(".js-set-cart").show();
			break;
			case "friend_show":
			$(".js-set-show-firend").show();
			break;
		}
    });	
	// 选择怎么猜的控件
	var zenmecai_val = [
          {text:'只猜是',value:'1'},
          {text:'只猜否',value:'2'},
          {text:'猜“是”、“否”',value:'3'},
          {text:'猜数据',value:'0'},
        ],
    zenmecai = new Select.Select({  
          render:'#s7',
          valueField:'.js-zmcval',
          items:zenmecai_val
        });
    zenmecai.render();
	zenmecai.on('change', function(ev){
		$(".js-zmctext").val(ev.text);
		var cffsval = $(".js-cffsval").val();
		if(cffsval=="win"||cffsval=="draw"){
			$(".js-target_data").hide();
		}else{
			$(".js-target_data").show();
			if(ev.value==0){
				$(".js-target_data").hide();
			}
		}
    });
	$(".js-multi").on("change",function(){
		var tp  = $(this).attr("data-tp");
		if($(this).val()==2){
			$(".multi-num-"+tp).show();
		}else{
			$(".multi-num-"+tp).hide();
		}
	});
	// 选择参赛队伍的控件
	if($(".js-player_json").val()){
	var players = JSON.parse($(".js-player_json").val());
	}
    var select_player = new Select.Select({  
          render:'#player',
          valueField:'.js-playerval',
          items:players
        });
    select_player.render();
	select_player.on('change', function(ev){
		$(".title").text(ev.item.title);
		if(ev.item.think_type_way==0){
			$(".target_data").text("和实际数据比较");
		}else{
			$(".target_data").text("和预设数据比较："+ev.item.target_data);
		}
		if(ev.item.think_type_way>0){ //只有猜数据的才计算差距
			select3.set("items",y_or_n);
			select3.render();
		}else{
			select3.set("items",score);
			select3.render();
		}
		
		if(ev.item.think_type_sign==='win' || ev.item.think_type_sign==='draw'){
			$(".js-target_data").hide();
		}else{
			$(".js-target_data").show();
		}
    });
	// 拖动选取奖品概率的控件
	 var slider = new Slider.Slider({
        render : '#sl1',
        max : 100000, //最大值
        value : 0 //当前值
      });
      slider.render();
      slider.on('change',function(ev){
        $('.js-jpgl').val(ev.value/1000);
      });
	  
	  // 拖动选择奖品数量的控件
	  var slider1 = new Slider.Slider({
        render : '#sl2',
        max : 1, //最大值
        value : 0 //当前值
      });
      slider1.render();
      slider1.on('change',function(ev){
        $('.js-jpsl').val(ev.value);
      });

	  // 拖动选择抽奖次数
	  var slider2 = new Slider.Slider({
        render : '#sl3',
        max : 10, //最大值
        value : 0 //当前值
      });
      slider2.render();
      slider2.on('change',function(ev){
        $('.js-cjcs').val(ev.value);
      });
		  var html = "";
			  html += ("<p>买家可通过签到、参与活动、奖品获得积分。");
			  html += ("如果您需要设置积分，请点击：</p>");
			  html += ("<ul class=\"toolbar\">");
			  html += ("<li><button class=\"button button-small\"><i class=\"icon icon-calendar\"></i>设置签到积分</button></li>");
			  html += ("<li><button class=\"button button-small\"><i class=\"icon icon-gift\"></i>设置积分奖品</button></li>");
			  html += ("</ul>");
          var dialog = new Overlay.Dialog({
            title:'积分消费说明',
            width:500,
            height:300,
            mask:false,
            buttons:[{
                text:'关闭',
                elCls : 'button',
                handler : function(){
                  this.close();
                }
              }
            ],
            bodyContent:html
          });
        $('.tipShow').on('click',function () {
          dialog.show();
        });
		// html = '';
		// html += "<center><p>当前比赛类型：<span class=\"label label-info\">奥运会</span> <span class=\"label label-info\">田径</span></p><p><input type=\"text\" ></p></center>";
		// var dialog1 = new Overlay.Dialog({
            // title:'添加猜分方式',
            // width:340,
            // height:170,
            // mask:true,
            // buttons:[{
                // text:'确定',
                // elCls : 'button offset3 pull-left',
                // handler : function(){
                  // caishenme.addChild({xclass:'select'});
                // }
              // }],
            // bodyContent:html
          // });
        $('.helper').on('click',function () {
			$msg = $(this).attr("data-msg");
			showDialog($msg);
        });
		
		var gift_number=0;
		var dialoggft = new Overlay.Dialog({
            title:'添加奖品',
            width:500,
            height:550,
            //配置DOM容器的编号
            contentId:'content',
            success:function () {
				gift_number++;
				var playerText = select_player.getSelectedText(); //猜哪支队伍
				var cffsText = select3.getSelectedText(); //猜分方式
				var hqfsText = select5.getSelectedText(); //获奖方式
				var giftText = $(".gift-name").val(); //奖品名称
				var qutyText = $(".js-jpsl").val(); //奖品数量
				var playerid = $(".js-playerval").val(); //猜分方式ID
				var cffs = $(".js-cfcj").val(); //猜分方式ID
				var cffsval = $(".js-cffsval").val(); //猜分方式ID
				var giftid = $(".gift-id").val(); //奖品ID
				var gifttp = $(".gift-type").val(); //奖品类型
				var hqfs = $(".js-hqfsval").val(); //获取方式ID
				var jpgl = $(".js-jpgl").val(); //奖品概率
				var cjcs = $(".js-cjcs").val(); //抽奖次数
				var ddje = $(".js-ddje").val(); //订单金额 
				var fksjks = $(".pay_time_start").val();// 订单付款开始时间
				var fksjjs = $(".pay_time_end").val();// 订单付款结束时间
				var gift_name = $(".gift-name").val();
				var pic_url = $(".js-gift_pic").val();
				var advance = $(".advance").val();
				var every_minute = $(".js-every-minute").val();
				var range_time_start = $(".range_time_start").val();
				var range_time_end = $(".range_time_end").val();
				var every_lotts = $(".js-every-lotts").val();
				var advance_quantity = $(".js-advance_quantity").val();
				var ext_rule = $(".js-ext-rule").val();
				var medal_id = $(".js-medalid").val();
				var medal_name = $(".js-medal_name").val();
				var medal_pic = $(".js-medal_pic").val();
				var rule_medalid = $(".js-rule_medalid").val();
				var rule_medal_name = $(".js-rule_medal_name").val();
				var rule_medal_pic = $(".js-rule_medal_pic").val();
				var medal_quant = $(".js-medal_quant").val();
				var show_title = $(".js-show-title").val();
				var show_content = $(".js-show-content").val();
				var jifen = $(".js-jifen").val();
				var payment = $(".js-payment").val();
				var pay_time_start = $(".pay_time_start").val();
				var pay_time_end = $(".pay_time_end").val();
				var level_num = $(".js-level_num").val();
				var level_name = $(".js-level_name").val();
				var collect_items = $(".collect_items").val();
				var order_items = $(".order_items").val();
				var cart_items = $(".cart_items").val();
				if(!playerText){alert($(".js-playerval").attr("data-msg"));return;}
				if(!cffs){alert($(".js-cfcj").attr("data-msg"));return;}
				if(!giftid){alert($(".gift-id").attr("data-msg"));return;}
				if(!hqfs){alert($(".js-hqfsval").attr("data-msg"));return;}
				$.ajax(
				{"url":"/?m=Kxdr&c=Gameset&a=save_gift",
					"data":{
					"cffsText":cffsText,
					"hqfsText":hqfsText,
					"giftText":giftText,
					"qutyText":qutyText,
					"playerid":playerid,
					"cffs":cffs,
					"cffsval":cffsval,
					"giftid":giftid,
					"gifttp":gifttp,
					"hqfs":hqfs,
					"jpgl":jpgl,
					"cjcs":cjcs,
					"ddje":ddje,
					"fksjks":fksjks,
					"fksjjs":fksjjs,
					"gift_name":gift_name,
					"pic_url":pic_url,
					"advance":advance,
					"every_minute":every_minute,
					"range_time_start":range_time_start,
					"range_time_end":range_time_end,
					"every_lotts":every_lotts,
					"advance_quantity":advance_quantity,
					"ext_rule":ext_rule,
					"medal_id":medal_id,
					"medal_name":medal_name,
					"medal_pic":medal_pic,
					"medal_quant":medal_quant,
					"rule_medalid":rule_medalid,
					"rule_medal_name":rule_medal_name,
					"rule_medal_pic":rule_medal_pic,
					"collect_items":collect_items,
					"order_items":order_items,
					"cart_items":cart_items,
					"show_title":show_title,
					"show_content":show_content,
					"jifen":jifen,
					"payment":payment,
					"pay_time_start":pay_time_start,
					"pay_time_end":pay_time_end
				  },
				  "type":"post",
				  "dataType": "json",
				  "success":function(data,status){
					if(data.hasError){
						showDialog("添加奖品出错！请联系客服："+data.error);
					}else{
						var html = "<div class=\"well well-small button-tabs gift"+data.gid+"\" ><div class=\"span13\">";
							html += "<button class=\"button button-mini\"><i class=\"icon icon-map-marker\"></i>"+playerText+"</button> ";
							html += "<button  class=\"button button-mini\"><i class=\"icon icon-certificate\"></i>"+cffsText+"</button> 的买家可 ";
						switch(hqfs){ 
							case "lottery" ://概率获奖
							html += "<button  class=\"button button-mini\"><i class=\"icon icon-star-empty\"></i>"+jpgl+"%"+"概率抽奖"+cjcs+"次</button>奖品";		  
							break;
							case "order_exchange" ://订单兑换
							html += "<button  class=\"button button-mini\"><i class=\"icon icon-shopping-cart\"></i>超过"+ddje+"元的订单号</button>兑换奖品";		  
							break;
							default :
							html += "<button  class=\"button button-mini\"><i class=\"icon icon-ok\"></i>"+hqfsText+"</button>奖品";		  
							break;
						}	  
							html += "<button  class=\"button button-mini\"><i class=\"icon icon-gift\"></i>"+giftText+"</button> 共 ";
							html += "<button  class=\"button button-mini\"><i class=\"icon icon-filter\"></i>"+qutyText+"名</button>";
							html += "&nbsp;<button  class=\"button button-mini button-warning js-delgift"+data.gid+" pull-right\" data-gnum=\""+gift_number+"\" data-gid=\""+data.gid+"\">删除</button>";
							html += "</div></div>";
						$(html).appendTo(".js-gift-list");
						$(".js-delgift"+data.gid).on("click",function(){
							var gid = $(this).attr("data-gid");
							removeGift(gid);
						});
						var record = giftstore.find('name',giftText);
						record.quantity = record.quantity - qutyText;
						record.text = giftText + "（"+record.quantity+"）";
						giftstore.update(record);
						select4.setSelectedValue();
						select4.setSelectedValue(record.id);
						$(".js-nogift").remove();
						dialoggft.close();
					}
					}
				});
			}
		});
        $('.js-addgift').on('click',function () {
          dialoggft.show();
        });
	   var uploader = new Uploader.Uploader({
        render: '#J_Uploader',
		name:"userfile",
        url: '/services/img/apiupload/SaveImg.php',
        //可以直接在这里直接设置成功的回调
        success: function(result){
			$(".js-picurl").val(result.url);
			$(".js-picview").attr("src",result.url+"_315x315.jpg");
        },
        //isSuccess : function(result){},
        //失败的回调
        error: function(result){
			showDialog("上传文件失败");
        }
      }).render();
      //上传成功时会触发
      // uploader.on('success', function(ev){
        // var result = ev.result;
      // })
 
      // //上传成功时会触发
      // uploader.on('error', function(ev){
        // var result = ev.result;
      // });
		$(".js-delgift").on("click",function(){
			var gid = $(this).attr("data-gid");
			removeGift(gid);
		});
		
		var items=new Array();
		var pg=1;
		$(".js-addgoods").on("click",function(){
			$.ajax(
				{"url":"/?q=&pg="+pg+"&numiids=&a=items&m=shopadmin&c=Service",
						"data":{},
					  "type":"post",
					  "dataType": "json",
					  "success":function(data,status){
							var html = "";
							var redbtn = "";
							for (var i=0;i<data.total_results;i++){
								redbtn="";
								for(var j=0;j<items.length;j++){
									if(items[j]==data.items.item[i].num_iid){
										redbtn="button-danger";
										break;
									}
								}
								html += "<table style=\"width:140px;float:left;margin-right:5px\" cellspacing=\"0\" class=\"table table-bordered table-item\">	<tbody>	<tr><td><div style=\"height:120px\"><a  href=\"http://item.taobao.com/item.htm?id="+data.items.item[i].num_iid+"\" target=\"_blank\"><img src=\""+data.items.item[i].pic_url+"_120x120.jpg\"></a></div>	<p class=\"centered\">"+data.items.item[i].title+"</p>	<div style=\"text-align:center\"><button type=\"button\" class=\"button button-small  js-select "+redbtn+" js-btn"+data.items.item[i].num_iid+"\" data-title=\""+data.items.item[i].title+"\" data-picurl=\""+data.items.item[i].pic_url+"\" data-iid=\""+data.items.item[i].num_iid+"\">选择</button></div>	</td></tr>	</tbody></table>";
							}
							var pgup_disa = pg>1?"":"disabled";
							var pgdwn_disa = pg<Math.ceil(data.total_results/20)?"":"disabled";
								html += ("<div class=\"pagination pull-right \" style=\"clear:both\">");
								html += ("<ul>");
								html += ("<li class=\""+pgup_disa+" js-pgup\"><a href=\"#\">« 上一页</a></li>");
								html += ("<li class=\""+pgdwn_disa+" js-pgdwn\"><a href=\"#\">下一页 »</a></li>");
								html += ("</ul>");
								html += ("</div>");
						  var dialoggft = new Overlay.Dialog({
								title:'添加推荐商品',
								width:930,
								height:600,
								//配置DOM容器的编号
								bodyContent:html,
							});
							dialoggft.show();
							// $(".js-pgdwn").on("click",function(){pg<Math.ceil(data.total_results/20)?(pg++ || $(".js-pgdwn").removeClass("disabled")):$(".js-pgdwn").addClass("disabled");alert(pg);});
							$(".js-pgdwn").on("click",function(){
								if(pg<Math.ceil(data.total_results/20)){
									pg++;
									dialoggft.destroy();
									$(".js-addgoods").fire("click");
									$(".js-pgdwn").removeClass("disabled")
								}else{
									$(".js-pgdwn").addClass("disabled")
								}
							});
							$(".js-pgup").on("click",function(){
								if(pg>1){
									pg--;
									dialoggft.destroy();
									$(".js-addgoods").fire("click");
									$(".js-pgup").removeClass("disabled");
								}else{
									$(".js-pgup").addClass("disabled");
								}
							});
							$(".js-select").on("click",function(){
								var numiid = $(this).attr("data-iid");
								for(var i=0;i<items.length;i++){
									if(numiid==items[i]){
										alert("已经推荐过这个商品了！");
										return;
									}
								}
								var pic_url = $(this).attr("data-picurl");
								var title = $(this).attr("data-title");
								var btn = [{
									text:'推荐',
									elCls : 'button button-success',
									handler : function(){
										var dialog = this;
										$.ajax(
										{"url":"/?m=Kxdr&c=Gameset&a=save_recom_items",
										"data":{
												"numiid":numiid,
												"tjbt":$(".js-tjbt").val(),
												"tjnr":$(".js-tjnr").val(),
												"pic_url":pic_url
												},
										"type":"post",
										"dataType": "json",
										"success":function(data,status){
										  $(".js-btn"+numiid).addClass("button-danger");
											var html = ("<div class=\"well well-small button-tabs js-item"+numiid+"\">");
											html+=("<div class=\"span3\"><img src=\""+pic_url+"_100x100.jpg\" height=\"100\" width=\"100\" class=\"pull-left\"></div>");
											html+=("<div class=\"span11\">");
											html+=("<button class=\"button button-mini button-danger pull-right js-delitem\" data-numid=\""+numiid+"\">删除</button>");
											html+=("<h1>"+$(".js-tjbt").val()+"</h1>");
											html+=("<p>"+$(".js-tjnr").val()+"</p>");
											html+=("</div>");
											html+=("</div>");
										  $(html).appendTo(".js-itemrecom");
										  $(".js-delitem").on("click",function(){
											  var ri = $(this).attr("data-numid");
											  remove_recomment(ri);
										  });
										  items.push(numiid);
										  dialog.destroy();
									  }});
									}
								  },{
									text:'取消',
									elCls : 'button',
									handler : function(){
										for(var i=0;i<items.length;i++){
											if(items[i]==numiid){
												items.splice(i,1);
												break;
											}
										}
										$(".js-btn"+numiid).removeClass("button-danger");
									  this.destroy();
									}
								  }];
								var html = '<div class=\"row\">';
									html +='<div class=\"control-group span12\">';
									html +='<label class=\"control-label span2\">推荐标题：</label>';
									html +='<div class=\"controls span4\">';
									html +='<input name=\"id\" type=\"text\" class=\"input-normal control-text js-tjbt \"  value=\"'+title+'\" aria-disabled=\"false\">';
									html +='<span class=\"auxiliary-text\">填入一个不一样的推荐标题</span>';
									html +='</div>';
									html +='</div>';
									html +='<div class=\"control-group span12\">';
									html +='<label class=\"control-label span2\">推荐内容：</label>';
									html +='<div class=\"controls span4\">';
									html +='<textarea class="input-large js-tjnr" type="text" aria-disabled="false" aria-pressed="false"></textarea>';
									html +='<span class=\"auxiliary-text\">填入推荐理由</span>';
									html +='</div>';
									html +='</div>';
									html +='</div>';
								showDialog1(html,"添加推荐商品",btn,500,300);
								// 将numiid推入数组：
								// if($(this).hasClass("button-danger")){
									// for(var i=0;i<items.length;i++){
										// if(items[i]==numiid){
											// items.splice(i,1);
											// break;
										// }
									// }
									// $(this).removeClass("button-danger");
								// }else{
									// items.push(numiid);
									$(this).addClass("button-danger");
								// }
							});
					  }
				});
				
		  });
		$(".js-delitem").on("click",function(){
			var ri = $(this).attr("data-numid");
			remove_recomment(ri);
		});
		function remove_recomment(numiid){
			var btn = [{
					text:'删除',
					elCls : 'button button-success',
					handler : function(){
						var dialog = this;
						$.ajax(
						{"url":"/?m=Kxdr&c=Gameset&a=remove_recom_item",
						"data":{"numiid":numiid},
						"type":"post",			
						"dataType": "json",
						"success":function(data,status){
							if(data.status==0){
								showDialog("删除推荐商品出错！请刷新页面后重试");
								return;
							}
							for(var i=0;i<items.length;i++){
								if(items[i]==numiid){
									items.splice(i,1);
									break;
								}
							}
							$(".js-item"+numiid).remove();
							dialog.destroy();
						}});
					}},{
					text:'取消',
					elCls : 'button ',
					handler : function(){
						this.destroy();
					}}];
			showDialog1("确实要删除吗？","删除推荐商品",btn,false,false,false,true);return;
			
		}
		$(".js-title-ex").on("click",function(){
			var html = "<ul>";
				html += "<li>易建联能抢几个篮板？</li>";
				html += "<li>上证指数这周能不能爬上6000点？</li>";
				html += "<li>21日的非诚勿扰男嘉宾总共被灭几盏灯？</li>";
				html += "<li>明天的撕名牌AB会不会出局？</li>";
				html += "<li>今年本省清华高考分数录取线是多少？</li>";
				html += "<li>今年双11本店销量能达到多少？</li>";
				html += "</ul>";
			showDialog(html);
		});
		$(".js-title-td").on("click",function(){
			var html = "<ul>";
				html += "<li>例子：进球是否能超过2个？预设数据为2，预测方向选择正向。</li>";
				html += "<li>例子：犯规是否不超过10次？预设数据为10，预测方向选择负向。</li>";
				html += "<li>只在针对数据猜是否的时候生效。</li>";
				html += "</ul>";
			showDialog(html);
		});
		$(".js-save").on("click",function(){
			var url = $(this).attr("data-url");
			var eid = $(".eid").val();
			var myes = $(".multi-yes").val();
			var mno = $(".multi-no").val();
			var mnyes = $(".multi-num-yes").val();
			var mnno = $(".multi-num-no").val();
			$.ajax(
				{"url":"/?m=Kxdr&c=Gameset&a=setmulti",
				"data":{"eid":eid,"myes":myes,"mno":mno,"mnyes":mnyes,"mnno":mnno},
				"type":"post",			
				"dataType": "json",
				"success":function(data,status){
				if(!data.hasError){
					location.href=url;
				}	
			}});
		});
		$(".js-get-metal").on("click",function(){
		var tp = $(this).attr("data-tp")?$(this).attr("data-tp")+"_":'';
		$.ajax(
		{"url":"/?m=Kxdr&c=medal&a=get_medal_as_gift",	
			"data":{"tp":tp},		
			"dataType": "json",
			"success":function(data,status){
				var msg="";
				if(data.hasError){
					msg="<h2>出错！</h2><br />"+data.error;
				}else{
					msg="<h2>请选择勋章：</h2><br /><div style=\"height:300px;overflow-y:scroll;\">";
					for(var i=0;i<data.data.length;i++){
						msg+='<li><span class="md'+data.data[i].id+'"><span> <img src="'+data.data[i].pic_url+'_20x20.jpg" />  '+data.data[i].title+'</span></span><button class="button button-mini umps" data-id="'+data.data[i].id+'" data-pic="'+data.data[i].pic_url+'" data-name="'+data.data[i].title+'" type="button">选择</button></li>';
					}
					msg+="</div>";
				}
				BUI.Message.Show({
					"msg" : msg,
					"icon" : 'question',
					"mask":false,
					"buttons" : [
					  {
						text:'确认',
						elCls : 'button button-mini js-msg',
						handler : function(){
						  this.close();
						}
					  },{
						text:'添加奖章',
						elCls : 'button button-mini',
						handler : function(){
							BUI.Message.Show({
								"msg" : "<h1>进入添加勋章</h1><br  /><div class=\"centered\"><a href=\"/?m=Kxdr&c=Medal\" target=\"_blank\" class=\"button button-big\">添加勋章</a></div>",
								"icon" : 'question',
								"mask":false,
								"buttons" : [
								]
							});
						}
					  }
					]
				});
				$(".umps").on("click",function(){
					$(".umps").removeClass("button-danger");
					$(this).addClass("button-danger");
					$(".js-giftname").val($(this).attr("data-name"));
					$(".js-"+tp+"medalid").val($(this).attr("data-id"));
					$(".js-"+tp+"medal_pic").val($(this).attr("data-pic"));
					$(".js-"+tp+"medal_name").val($(this).attr("data-name"));
					$("."+tp+"medal").empty();
					$($(".md"+$(this).attr("data-id")).html()).appendTo("."+tp+"medal");
					$(".js-"+tp+"medal_c").removeClass("hide");
					$(".js-"+tp+"medal").addClass("hide");
					var html = "直接出现在勋章列表";
					$(".js-detail").val(html);
					$(".js-msg").click();
					$(".js-giftname").blur();
				});
			}
		});
	});
	$(".js-itemset").on("click",function(){
		getitems("","","","collect_items",10);
	});
	$(".js-cartset").on("click",function(){
		getitems("","","","cart_items",10);
	});
	$(".js-orderset").on("click",function(){
		getitems("","","","order_items",10000);
	});
	function getitems(q,pg,numiids,input,limit){
		Q=q?q:"";
		PG=pg?pg:1;
		limit=limit?limit:1;
		input=input?input:"order_items";
		showDialog("正在读取数据。。。","<img src=\"http://gtd.alicdn.com/tps/i3/T1b1m3XkVpXXXXXXXX-32-32.gif\" />","form-horizontal");	
		var item_iids = $('.'+input).val();
		if(item_iids!=""){
		num_iids = JSON.parse(item_iids);
		}else{
		num_iids=new Array();
		}
		$.ajax({
			url: "/?a=items&m=shopadmin&c=Service",
			data:{"q":Q,"pg":PG,"numiids":numiids},
			success: function(data, textStatus) {
			closeDialog();
			if(data.code){
				showDialog("读取失败！",data.msg+data.sub_msg,"form-horizontal");
				return;
			}
			if(data.total_results==0){
				showDialog("读取失败！","没有读取到任何商品哦！","form-horizontal");
			}else{
				var item="<input type=\"text\" value=\""+data.q+"\" class=\"js-gjc\" /><button type=\"button\" class=\"button button-mini js-so\">搜索</button>  共"+data.total_results+"件商品  <button type=\"button\" class=\"button button-mini button-success js-ready\" data-input=\""+input+"\">查看已设置的商品</button> <button type=\"button\" class=\"button button-mini js-ready-all\">查看全部</button> <!--button type=\"button\" class=\"button button-mini js-select-all\">全选本页</button-->";
				item +=("<hr style=\"clear:both\">");
				for(var i=0;i<data.items.item.length;i++){
				item +=("<table style=\"width:140px;float:left;margin-right:5px\" cellspacing=\"0\" class=\"table table-bordered table-item\">");
				item +=("	<tbody>");
				item +=("	<tr><td>");
				item +=("		<a href=\"http://item.taobao.com/item.htm?id="+data.items.item[i].num_iid+"\" target=\"_blank\" ><img src=\""+data.items.item[i].pic_url+"_120x120.jpg\"></a>");
				// item +=("	</td></tr><tr><td>");
				item +=("	商品标题："+data.items.item[i].title);
				var css = "";
				var text = "选择";
				for (var j=0;j<num_iids.length;j++){
					if(data.items.item[i].num_iid==num_iids[j]){
						css = "button-danger";
						text = "取消选择";
						break;
					}
				}
				item +=("	<div style=\"text-align:center\"><button type=\"button\" class=\"button button-small "+css+" js-select\" data-price=\""+data.items.item[i].price+"\" data-title=\""+data.items.item[i].title+"\" data-pic=\""+data.items.item[i].pic_url+"\" data-iid=\""+data.items.item[i].num_iid+"\">"+text+"</button></div>");
				item +=("	</td></tr>");
				item +=("	</tbody>");
				item +=("</table>");
				}
				item +=("<hr style=\"clear:both\">");
				item +=("<div class=\"centered\"><button type=\"button\" class=\"button button-mini js-pgup\">上一页</button>");
				item +=("<button type=\"button\" class=\"button button-mini js-pgdown\">下一页</button></div>");
				showDialog("请选择商品",item,"form-horizontal");
				$(".js-ready-all").on("click",function(){
					getitems("","","",$(this).attr("data-input"),limit);
				});
				$(".js-select-all").on("click",function(){
					$(".js-select").fire("click");
				});
				$(".js-select").on("click",function(){
					if(num_iids.length>=limit && !$(this).hasClass("button-danger")){
						alert("只能选择"+limit+"件商品！");
						return;
					}
					var key = $(this).attr("data-iid");
					var pic = $(this).attr("data-pic");
					var title = $(this).attr("data-title");
					var price = $(this).attr("data-price");
					var item_json = new Array(key,pic,title,price);
						// alert(JSON.stringify(item_json));
					if($(this).hasClass("button-danger")){
						for(var i=0;i<num_iids.length;i++){
							if(num_iids[i][0]==key){
								num_iids.splice(i,1);
							}
						}
						$("."+input).val(encodeURI(JSON.stringify(num_iids)));
						$(this).removeClass("button-danger");
						$(this).text("选择");
						$(".items-"+input).text(num_iids.length);
					}else{
						num_iids.push(item_json);
						$("."+input).val(encodeURI(JSON.stringify(num_iids)));
						$(this).addClass("button-danger");
						$(this).text("取消选择");
						$(".items-"+input).text(num_iids.length);
					}
				});
				$(".js-pgup").on("click",function(){
					if(PG==1){
						alert("没有上一页啦！");
					}else{
						PG--;
						getitems($(".js-gjc").val(),PG,numiids,input,limit);
					}
				});
				$(".js-pgdown").on("click",function(){
					if(PG>(data.total_results/20)){
						alert("没有下一页啦！");
					}else{
						PG++
						getitems($(".js-gjc").val(),PG,numiids,input,limit);
					}
				});
				$(".js-ready").on("click",function(){
					var item_iids = $('.'+input).val();
					if(!item_iids){
					alert("您还没有选择任何商品！");
					}else{
					getitems("","",item_iids,input,limit);
					}
				});
			}
			$(".js-so").on("click",function(){
				getitems($(".js-gjc").val(),"","",input,limit);
			});
			},
			complete: function(data){
				
			},
			error: function(){
				alert('error');
			},
			dataType:"json"
		});
	}
	function closeDialog(title,msg,input){
		$(".js-close").click();
	}
	$(".js-cancel-metal").on("click",function(){
		$(".js-rule_medalid").val("");
		$(".js-rule_medal_name").val("");
		$(".js-rule_medal_pic").val("");
		$(".js-rule_medal").removeClass("hide");
		$(this).addClass("hide");
		$(".rule_medal").empty();
	});
});